#pragma once

#include <iostream>
#include <string>
#include <stdarg.h>
#include <time.h>

//日志级别
#define DEBUG 0
#define NORMAL 1
#define WARNING 2
#define ERROR 3
#define FATAL 4

const char* gLevelMap[] = { "DEBUG", "NORMAL", "WARNING", "ERROR", "FATAL" };

void logMessage(int level, const char* format, ...)
{
#ifndef DEBUG_SHOW
    if(level == DEBUG) return;
#endif
    char stdBuffer[1024];//标准部分
    time_t timestamp = time(nullptr);
    snprintf(stdBuffer, sizeof(stdBuffer), "[%s] [%ld] ", gLevelMap[level], timestamp);

    char longBuffer[1024];//自定义部分
    va_list args;
    va_start(args, format);
    vsnprintf(longBuffer, sizeof(longBuffer), format, args);
    va_end(args);

    printf("%s%s\n",stdBuffer,longBuffer);
}